package com.yi.zsb.handler;

import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class Studenthandler implements SOAPHandler<SOAPMessageContext> {

	@Override
	public Set<QName> getHeaders() {
		return null;
	}

	@Override
	public void close(MessageContext cxt) {
		
	}

	@Override
	public boolean handleFault(SOAPMessageContext cxt) {
		return false;
	}

	@Override
	public boolean handleMessage(SOAPMessageContext cxt) {
		
		 Boolean out = (Boolean) cxt.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY);
		 
		 try {
			if(out){
				 
				 SOAPEnvelope envelope = cxt.getMessage().getSOAPPart().getEnvelope();
				 SOAPHeader head = envelope.getHeader();
				 
				 if(head == null){
					 head = envelope.addHeader() ;
					 QName qname = new QName("http://ws.service.yi.com/" , "lenceInfo" ,"ns");
					 
				//	 head.addHeaderElement(qname).setValue("admin");
					 
				 }
				 
			 } //开始添加头信息
		} catch (SOAPException e) {
			e.printStackTrace();
		}
			 
	
		 System.out.println("out====" + out);
		return true;
	}

}
